package com.lwj.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lwj.entity.LoginUser;
import com.lwj.entity.User;
import com.lwj.mapper.UserMapper;
import com.lwj.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.UUID;


/**
 * @author: lwj
 * @description:
 **/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public LoginUser findUser(User vo) {
        LoginUser loginUser = new LoginUser();
        String token = UUID.randomUUID().toString();
        loginUser.setToken(token);
        System.out.println(SecureUtil.md5(vo.getPassword()));
        User user = this.getOne(new QueryWrapper<User>().eq("username", vo.getUsername()));
        if(user==null) return null;
        if (SecureUtil.md5(vo.getPassword()).equals(user.getPassword())) {
            loginUser.setUser(user);
            return loginUser;
        }
        return null;
    }
}
